                            # 5.1 一个简单示例
cars = [ 'audi', 'bmw', 'subaru', 'toyota' ]
for car in cars :
    if car == 'bmw' : # 检查当前的汽车名是否是'bmw'
        print( car.upper() ) # 是的话，以全大写的方式打印
    else :
        print( car.title() ) # 否则以首字母大写的方式打印
                            # 5.2 条件测试
# 5.2.1 检查是否相等
car = 'audi'
print( "\n" )
print( car == 'audi' ) # -> True
print( car == 'bmw' )  # -> False
# 5.2.2 检查是否相等时不考虑大小写
print( "\n" )
print( car == 'AUDI' ) # -> False
print( car.upper() == 'AUDI' ) # -> True
# 5.2.3 检查是否不相等
requested_topping = 'mushroom'
if requested_topping != 'anchovies' :
    print( "\nHold the anchovies!" )
# 5.2.4 比较数字
answer = 17
if answer != 18 :
    print( "\nThat is not the correct answer. Please try again!" )
# 5.2.5 检查多个数字
answer1 = 40
answer2 = 58
if (answer1 != 10) and (answer2 != 18) :
    print( "\nThese are not the correct answers. Please try again!" )
# 5.2.6 检查特定值是否包含在列表中
    # 关键字：in
requested_toppings = [ 'mushrooms', 'onions', 'pineapple' ]
if 'mushrooms' in requested_toppings :
    print( "\nTrue!" )
# 5.2.7 检查特定值是否不包含在列表中
banned_users = [ 'andrew', 'carolina', 'david' ]
user = 'marie'
if user not in banned_users :
    print( user.title() + ", you can post a response if you wish." )
# 5.2.8 布尔表达式
game_active = True  # 记录游戏是否在运行
can_edit = False    # 记录用户是否可以编辑网站的特定内容
                            # 5.3 if语句
# 5.3.1 简单的if语句
    # if conditional_test :
        # do something
age = 22
if age >= 18 :
    print( "\nYou are old enough to vote!" )
    print( "Have you registered to vote yet?\n" )
# 5.3.2 if-else语句
else:
    print( "\nSorry, you are too young to vote!" )
    print( "Please register to vote as soon as you turn 18!\n" )
# 5.3.3 if-elif-else 结构
    # 只执行一个代码块
age = int( input( "\nPlease enter your age:" ) )
if age < 4 :
    price = 0
elif age < 18 :
    price = 5
elif age < 65 :
    price = 10
else :
    price = 5
print( "Your admission cost is $" + str(price) + ".\n" )
                            # 5.4 使用if语句处理列表
# 5.4.1 检查特殊元素 & 5.4.2 确定列表不是空的
requested_toppings = [ 'mushrooms', 'green peppers', 'extra cheese' ]
available_toppings = []
if available_toppings :
    for requested_topping in available_toppings :
        if requested_topping == 'green peppers' :
            print( "Sorry, we are out of green peppers right now." )
        else :
            print( "Adding " + requested_topping + "." )
    print( "\nFinished making your pizza!" )
else :
    print( "Are you sure want a plain pizza?\n" )
# 5.4.3 使用多个列表
new_available_toppings = [ 'mushrooms', 'olives', 'green peppers', 'pepperoni',
                            'pineapple', 'extra cheese' ]
requested_toppings = [ 'mushrooms', 'french fries', 'extra cheese', 'anchovies' ]

for requested_topping in requested_toppings :
    if requested_topping in new_available_toppings :
        print( "Adding " + requested_topping + "." )
    else :
        print( "Sorry, we don't have " + requested_topping + "." )
print( "\nFinished making your pizza!" )

